from xinan_ui.proxy.base_page import PageHandle
import time

from selenium.webdriver.common.by import By

from xinan_ui.proxy.base_page import PageHandle
from xinan_ui.tools.read_yml_xn import ReadYaml
import logging

data_eles = ReadYaml('../config/xnapp.yml').read_yaml()['手机号登录页']

class PhoneLoginUi(PageHandle):
    def __init__(self,driver):
        self.driver=driver
        super().__init__(self.driver)

    def phone_login(self,phone):
        try:
            self.click_button(data_eles[0]['新股新债提示框'])
            time.sleep(3)
            logging.info("出现新股新债提示框")
        except:
            print("没有出现新股新债提示框")
            logging.info("没有出现新股新债提示框")

        try:
            self.click_button(data_eles[1]['升级提示提示框'])
            time.sleep(3)

        except:
            print("没有出现升级提示提示框")
            logging.info("没有出现升级提示提示框")
        logging.info("开始进入手机登录")

        self.click_button(data_eles[2]['交易登录按钮'])
        time.sleep(3)
        self.input_element(data_eles[3]['手机号输入框'],phone)
        time.sleep(3)

        self.click_button(data_eles[4]['勾选隐私协议按钮'])
        time.sleep(5)
        self.click_button(data_eles[5]['获取验证码按钮'])
        time.sleep(5)
        self.input_element(data_eles[6]['验证码输入框'], '123456')
        time.sleep(4)
        self.click_button(data_eles[7]['确定按钮'])
        time.sleep(5)
        logging.info("手机号登录成功")